<?php
class Theme_Node extends Model_Theme {
    private $viewSimple;
    /**
     * 返回node输出， $variables = array(node => node_array, variable_name => value,...)
     * @param array $variables
     */
    function themeNodeView($variables) {
        $this->viewSimple = new FLEA_View_Simple(dirname(FLEA::getFilePath('View_NodeView')));
        $this->viewSimple->assign($variables);
        ob_start();
        $this->viewSimple->display('NodeView.php', md5(serialize($variables)));
        $content = ob_get_contents();
        ob_get_clean();
        return $content;
    }
    function themeAddNode($variables = NULL) {
        $this->viewSimple = new FLEA_View_Simple(dirname(FLEA::getFilePath('View_NodeView')));
        $this->viewSimple->cleanAllCache();
        $this->viewSimple->assign($variables);
        ob_start();
        $this->viewSimple->display('AddNode.php', md5(serialize($variables)));
        $content = ob_get_contents();
        ob_get_clean();
        return $content;
    }
    /**
     * 生成文章预览项，构成文章列表
     * @param array $variables
     */
    function themeNodeListItem($variables = NULL) {
        return $this->_themeNode('NodeListItem.php', $variables);
    }
    /**
     * 生成文章预览列表
     * @param array $variables
     */
    function themeNodeList($variables) {
        return $this->_themeNode('NodeList.php', $variables);
    }

    private function _themeNode($template ,$variables = NULL) {
        $this->viewSimple = new FLEA_View_Simple(dirname(FLEA::getFilePath('View_NodeView')));
        $this->viewSimple->assign($variables);
        ob_start();
        $this->viewSimple->display($template, md5(serialize($variables)));
        $content = ob_get_contents();
        ob_get_clean();
        return $content;
    }
}
